package com.huhu.controller;

import com.huhu.controller.base.BaseController;
import com.huhu.dto.Result;
import com.huhu.entity.User;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

/**
 * Created by xuyi on 2016/9/19.
 */
@Controller
@RequestMapping("lab1Ctrl")
public class Lab1Ctrl extends BaseController {

    @RequestMapping("click")
    @ResponseBody
    public Result click() {
        Result rst = new Result();

        Session session = SecurityUtils.getSubject().getSession();
        User user = (User) session.getAttribute("user");

        if (user != null) {
            rst.setFlag(1);
            rst.setContent(user.getUserId());
        } else {
            Date lastAccessTime = session.getLastAccessTime();
            System.out.println(lastAccessTime.getTime());
            rst.setFlag(-2);
            rst.setContent("Session中没有User," + session.getTimeout());
        }

        return rst;
    }



}
